package com.dhecp.project.finance.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.finance.domain.AccountCountForUserHistory;
import com.dhecp.project.finance.service.AccountCountForUserHistoryService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 用户历史资金 控制层
 * @author DH-Xxj
 * @version 2022年10月19日
 */
@Controller
@RequestMapping("/finance/accountcountforuserhistory")
public class AccountCountForUserHistoryController extends BaseModuleController{

    private String moduleTable = "TCW_ACCOUNTCOUNTFORUSERHISTORY";
    
    @Autowired
    private AccountCountForUserHistoryService businessService;
    
    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;
    
    /**
     * 打开查询列表页
     * @param params
     * @return
     * @author DH-Xxj 
     */
	@RequiresPermissions("finance:accountcountforuserhistory:view")
    @GetMapping()
    public ModelAndView listPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	params.put("entity", new AccountCountForUserHistory()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
    	params.put("prefix","finance/finance"); //页面路径
    	
    	ModelAndView mv = this.openListPage(params);
    	mv.addObject("finance", "accountcountforuserhistory");
		return mv;
    }

	/**
	 * 查询页 列表数据
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("finance:accountcountforuserhistory:list")
	@GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
        List<AccountCountForUserHistory> list = new ArrayList<AccountCountForUserHistory>();
        try {
        	list = businessService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }

    /**
     * 数据导出Excel
     * @param params
     * @return
     * @throws Exception
     * @author DH-Xxj
     */
    @RequiresPermissions("finance:accountcountforuserhistory:export")
    @Log(title = "用户历史资金导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
		params.put("moduleTable", moduleTable);
    	params.put("entity", new AccountCountForUserHistory()); 
    	
        List<AccountCountForUserHistory> list = businessService.queryList(params);
        
    	params.put("getFieldAttributesType", "export");
    	List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<AccountCountForUserHistory> util = new ExportExcelUtils<AccountCountForUserHistory>(moduleTable,new AccountCountForUserHistory());
        return util.exportExcel(list, fieldList, "用户历史资金", "export");
    }
    
}
